package com.ruoyi.jproom.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.jproom.entity.Housing;
import com.ruoyi.jproom.entity.Residential;
import com.ruoyi.jproom.entity.Sell;
import com.ruoyi.jproom.service.ResidentialService;
import com.ruoyi.jproom.utils.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author zeo
 * @explain 小区控制层
 * @date 2020/7/29 8:30
 */
@Controller
@RequestMapping("/residential")
public class ResidentialController extends BaseController {

    private String prefix = "residentialmanage";

    @Autowired
    private ResidentialService residentialService;

    /**
     * 客户端获取所有小区信息
     *
     * @return
     */
    @RequestMapping("/findResidentList")
    @ResponseBody
    public BaseResult findResidentList(Residential residential) {
        return residentialService.findResidentList(residential);
    }

    /**
     * 跳转小区管理界面
     * @return
     */
    @GetMapping("/toResidentialManage")
    public String toResidentialManage() {
        return prefix + "/residentialManage";
    }

    /**
     * 服务端获取所有小区信息
     *
     * @return
     */
    @RequestMapping("/serverFindResidentList")
    @ResponseBody
    public TableDataInfo serverFindResidentList(Residential residential) {
        return getDataTable(residentialService.serverFindResidentList(residential));
    }

    /**
     * 修改小区数据
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/residentEdit/{id}")
    public String residentEdit(@PathVariable("id") String id, ModelMap mmap) {
        Residential residential = residentialService.findResidentByResidentialId(id);
        mmap.put("residential",residential);
        return prefix + "/residentEdit";
    }

    @RequestMapping("/rentResidentialEdit")
    @ResponseBody
    public AjaxResult rentResidentialEdit(Residential residential){
        return toAjax(residentialService.rentResidentialEdit(residential));
    }

    @RequestMapping("/deleteImage")
    @ResponseBody
    public AjaxResult deleteImage(){
        System.out.println("aaaa");
        return toAjax(0);
    }
}
